var record_index = 0;
var int          = null;
function auto_slideshow_product(){
	var photos = $.makeArray($('.product-detail-gallery li'));
	if(record_index > photos.length - 1){
		record_index = 0;
		}
		var large_img   = $(photos[record_index]).find('a').attr('large_img');
                var small_img   = $(photos[record_index]).find('a').attr('small_img');

                $('.product-detail-gallery li').find('a').css({
                            'color': '#000',
                            'font-weight': 'normal'
                });
                $(photos[record_index]).find('a').css({
                            'color': '#F00',
                            'font-weight': '700'
                });
		$('#product-detail-slideshow-gallery').attr('href',large_img);
                $('#product-detail-slideshow-gallery').fadeOut(1200, function(){
                    $('#product-detail-slideshow-gallery').find('img').attr('src',small_img);
                    $('#product-detail-slideshow-gallery').fadeIn(500);
                });
                
		record_index++;
		int = setTimeout(function(){
		auto_slideshow_product();
		},7000);
}

function start_slideshow_product(){
        var photos = $.makeArray($('.product-detail-gallery li'));
        if(photos.length <=1){
            return;
        }
	$.each(photos, function(index, el){
		$(el).click(function(){
			clearTimeout(int);
                        var large_img   = $(el).find('a').attr('large_img');
                        var small_img   = $(el).find('a').attr('small_img');
                        $('#product-detail-slideshow-gallery').attr('href',large_img);
                        $('#product-detail-slideshow-gallery').fadeOut(1200, function(){
                            $('#product-detail-slideshow-gallery').find('img').attr('src',small_img);
                            $('#product-detail-slideshow-gallery').fadeIn(500);
                        });
                        $('.product-detail-gallery li').find('a').css({
                            'color': '#000',
                            'font-weight': 'normal'
                        });
                        $(el).find('a').css({
                            'color': '#F00',
                            'font-weight': '700'
                        });
			record_index	=	index;
                        auto_slideshow_product();
		});
	});
        if($('#product-detail-slideshow-gallery').attr('id')){
            setTimeout(function(){
		auto_slideshow_product();
            },6000);
        }
        //lightbox in product detail
        if($('#product-detail-slideshow-gallery').attr('id')){
            $('#product-detail-slideshow-gallery').lightBox({fixedNavigation: true});
        }
}
